// vite.config.ts
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import path from "path";
// 引入svg需要用到的插件
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import { viteMockServe } from "vite-plugin-mock";

// command用于获取当前开发环境。mock接口只用于开发
export default defineConfig(({ command }) => {
  return {
    plugins: [
      vue(),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
        symbolId: "icon-[dir]-[name]",
      }),
      viteMockServe({
        localEnabled: command === "serve", //开发阶段可以使用mock接口
      }),
    ],
    resolve: {
      alias: {
        "@": path.resolve("./src"),
      },
    },
    // scss全局变量配置
    css: {
      // 配置预处理器选项
      preprocessorOptions: {
        scss: {
          // 启用 JavaScript
          javascriptEnabled: true,
          // 全局数据（变量、混入等）
          additionalData: '@import "./src/styles/variables.scss";',
        },
      },
    },
  };
});
